#include "Rect.h"

using namespace SolidityEngine;

Rect::Rect(float left, float right, float width, float height):
    _x(left),
    _y(right),
    _w(width),
    _h(height)
{}

Rect::~Rect(){}

float& Rect::X()
{
    return _x;
}

float Rect::X() const
{
    return _x;
}

float& Rect::Y(){
    return _y;
}

float Rect::Y() const{
    return _y;
}

float& Rect::Width(){
    return _w;
}

float Rect::Width() const{
    return _w;
}

float& Rect::Height(){
    return _h;
}

float Rect::Height() const{
    return _h;
}

void Rect::Set(float left, float right, float width, float height){
    _x=left;
    _y=right;
    _w=width;
    _h=height;
}

///Get the center point on the screen
Vector2D Rect::GetCentre() const{
    return Vector2D(_x+(_w/2),_y+(_h/2));
}

///Set the location of the surface by adjusting the centre point
void Rect::SetCentre(const Vector2D& point){
    _x=point.X()-(_w/2);
    _y=point.Y()-(_h/2);
}

///Return true if the Rect contains the given point.
bool Rect::Contains(const Vector2D& point)const {
    if((point.X()>_x && point.X()<(_x+_w)) && (point.Y()>_y && point.Y()<(_y+_h))){
        return true;
    }
    return false;
}


Vector2D* Rect::GetPoints(){
    Vector2D points[4];
    points[0] = Vector2D(_x,_y);
    points[1] = Vector2D(_x+_w,_y);
    points[2] = Vector2D(_x+_w,_y+_w);
    points[3] = Vector2D(_x,_y+_w);
    return points;
};

Vector2D* Rect::GetPoints() const{
    Vector2D points[4];
    points[0] = Vector2D(_x,_y);
    points[1] = Vector2D(_x+_w,_y);
    points[2] = Vector2D(_x+_w,_y+_w);
    points[3] = Vector2D(_x,_y+_w);
    return points;
};

bool Rect::operator==(const Rect& rhs) const{
    if((this->_x == rhs._x)&&(this->_y == rhs._y)&&(this->_w == rhs._w)&&(this->_h==rhs._h)){
        return true;
    }
    return false;
}

bool Rect::operator!=(const Rect& rhs) const {
    if(*this==rhs){
        return false;
    }
    return true;
}
